<?php

class Zend_View_Helper_ProductSpecifications extends Zend_View_Helper_Abstract
{

	/**
	 * @param string $specifications
	 * @return string
	 */
	public function productSpecifications($specifications)
	{
		$specifications = trim($specifications);
		if(!empty($specifications)) {
			$lines = preg_split('#(\r\n?|\n)#', $specifications);
			if(count($lines) > 0) {
				$definitions = '';
				foreach($lines AS $line) {
					preg_match('#^(.+?)\s*\:\s*(.+)$#', $line, $matches);
					if(isset($matches[1]) && isset($matches[2])) {
						$definitions .= sprintf('<dt>%s</dt><dd>%s</dd>', $matches[1], $matches[2]);
					}
				}
				if(!empty($definitions)) {
					return sprintf('<dl>%s</dl>', $definitions);
				}
			}
		}
		return '';
	}

}